package com.dc.web.controller.constant;

import com.dc.dao.constant.InWuWaterStaticConstantDao;
import com.dc.entity.constant.InWuWaterStaticConstantEntity;
import com.dc.model.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 常量表。数据不会变，只是用来看的
 */
@RestController
@RequestMapping("/api/constant")
@Slf4j
public class ConstantTableController {

    @Resource
    private InWuWaterStaticConstantDao inWuWaterStaticConstantDao;

    /**
     * 坞内用水量
     * @return
     */
    @GetMapping("/wu_in/water/list")
    public AjaxResult get() {
        List<InWuWaterStaticConstantEntity> all = inWuWaterStaticConstantDao.findAll();
        Double sum = all.stream().mapToDouble(InWuWaterStaticConstantEntity::getWater).sum();
        Map<String, Object> result = new HashMap<>();
        result.put("sum", sum);
        result.put("data", all);

        return AjaxResult.success(result);
    }
}
